<?php
/**
 * BaseIterator
 *
 * All iterator-based processor should be this class descendats.
 *
 * @author  Badrus Said <badrus.said@gmail.com>
 * @since   gop1.0
 */
final class gop_BaseIterator extends gop_Base {
    public function interupt($k = 0, $v = 1) {
        call_user_func(array($this, ($k == 0) ? "setContinue" : "setBreak"), $v);
    }
    public function interuptContinue() {
        $this->setContinue($this->getContinue() - 1);
        if ($this->getContinue() == 0) return;
        $caller = $this->getCaller();
        while($caller) {
            if ($caller instanceof gop_BaseIterator) {
                $caller->interupt(0, $this->getContinue());
                break;
            }
            $caller = $caller->getCaller();
        }
    }
    public function interuptBreak() {
        $this->setBreak($this->getBreak() - 1);
        if ($this->getBreak() == 0) return;
        $caller = $this->getCaller();
        while($caller) {
            if ($caller instanceof gop_BaseIterator) {
                $caller->interupt(1, $this->getBreak());
                break;
            }
            $caller = $caller->getCaller();
        }
    }
}
?>